#include<iostream>
#include<unistd.h>
#include<signal.h>

void Print(sigset_t pending)
{

    for(int signo=31;signo>0;signo--)
    {
        if(sigismember(&pending,signo))
        {
            std::cout<<1;
        }
        else
        {
            std::cout<<0;
        }
    }
    std::cout<<"\n";
}
void handler(int signo)
{
    std::cout<<"get a sig: "<<signo <<std::endl;
    while(true)
    {
        sigset_t pending;
        sigpending(&pending);             //再次接收一下pending信号集
        Print(pending);                   //打印显示
        sleep(1);
    }
    exit(1);
}

int main()
{
    struct sigaction act,oact;
    act.sa_handler = handler;                //
    sigemptyset(&act.sa_mask);             
    act.sa_flags = 0;
    sigaction(2,&act,&oact);

    while(true)
    {
        std::cout<<"I am a process, pid: "<<getpid()<<std::endl;

        sleep(1);
    }
    return 0;
}

